﻿using CCManger.Common.Message;
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using System.Collections.Generic;

namespace CCManger.Common.Coder
{
    public class CommonDecoder : ByteToMessageDecoder
    {
        protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
        {
            byte[] array = new byte[input.ReadableBytes];
            input.GetBytes(input.ReaderIndex, array, 0, input.ReadableBytes);
            input.Clear();
            var temp = MessagePackHelper.DeserializeWithBinary<CCManger.Common.Message.Message>(array);
            output.Add(temp);
        }
    }
}